<?php

/**
 * This is the model class for table "zy_fandian".
 *
 * The followings are the available columns in table 'zy_fandian':
 * @property integer $id
 * @property integer $agent_type
 * @property integer $min
 * @property integer $max
 * @property string $rate
 * @property string $remark
 * @property integer $is_delete
 * @property integer $creater
 * @property string $createtime
 * @property string $updatetime
 * @property integer $updater
 */
class Fandian extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return Fandian the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'zy_fandian';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('rate', 'required'),
			array('agent_type, min, max, is_delete, creater, updater', 'numerical', 'integerOnly'=>true),
			array('rate', 'length', 'max'=>11),
			array('remark', 'length', 'max'=>255),
			array('createtime, updatetime', 'safe'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, agent_type, min, max, rate, remark, is_delete, creater, createtime, updatetime, updater', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'agent_type' => Yii::t('base','Agent Type'),
			'min' => Yii::t('base','Min'),
			'max' => Yii::t('base','Max'),
			'rate' =>Yii::t('base','Rate'),
			'remark' => 'Remark',
			'is_delete' => Yii::t('base','Is Delete'),
			'creater' => 'Creater',
			'createtime' => 'Createtime',
			'updatetime' => 'Updatetime',
			'updater' => 'Updater',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('agent_type',$this->agent_type);
		$criteria->compare('min',$this->min);
		$criteria->compare('max',$this->max);
		$criteria->compare('rate',$this->rate,true);
		$criteria->compare('remark',$this->remark,true);
		$criteria->compare('is_delete',$this->is_delete);
		$criteria->compare('creater',$this->creater);
		$criteria->compare('createtime',$this->createtime,true);
		$criteria->compare('updatetime',$this->updatetime,true);
		$criteria->compare('updater',$this->updater);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
	public function updateFandian(){
		$agent_type=$_POST['Fandian']['agent_type'];
		$min=$_POST['Fandian']['min'];
		$max=$_POST['Fandian']['max'];
		$fandian=Fandian::model()->find('agent_type='.$agent_type.' AND min='.$min.' AND max ='.$max.' AND is_delete=0');
		$fandian->is_delete=1;
		$fandian->update();
		return $fandian;
	}
}